#include <time.h>
#include <cstdlib>
#include "SmallCover.h"

using namespace std;


static bool isIn(vector<int> v, int val)
{
  for(int i = 0; i<v.size(); i++)
    if(v[i] == val)
      return true;
  return false;
}

SmallCover::SmallCover(int n, int coverSize, double p)
{
  srand(time(NULL));
  vector<int> cover;
  for(int i =0; i<coverSize; i++)
    {
      int j = rand() % n;
      if(!isIn(cover, j))
	{
	  cover.push_back(j); 
	}
      else
	i--;
    }

  for (int i = 0; i < n; i++)
    {
      addVertex();
    }
  cout << "\nPetite Couverture : ";
  for (unsigned i = 0; i < cover.size(); i++)
    {
      cout << cover[i] << " ";
    }
  cout << endl;
  for (int i = 0; i < cover.size(); i++)
    {
      for (int j = 0; j < adgencyList.size(); j++)
	{
	  if (cover[i] == j) continue;
	  double r = rand()/(double)RAND_MAX;
	  if(r < p && !isEdge(cover[i], j))
	    {
	      addEdge(cover[i], j);
	    }
	}
    }
}

SmallCover::SmallCover(const SmallCover& other):AbstractGraph(other)
{
}
